#!/usr/bin/env python2.7
# _*_ coding:UTF-8 _*_
"""
__author__ = 'shede333'

检测忽略、注释
"""

from functools import wraps

_g_is_in_comment_star_status = False
_g_is_in_custom_ignore_status = False


def reset_all_ignore_flag():
    """
    重置"检测注释"的标志位
    :return:
    """
    global _g_is_in_comment_star_status
    global _g_is_in_custom_ignore_status
    _g_is_in_custom_ignore_status = False
    _g_is_in_comment_star_status = False


def comment_star_decorator(f):
    """
    检测"/* */"注释代码的装饰器
    :param f: 被装饰的函数
    :return: 装饰器
    """
    @wraps(f)
    def decorator(tmp_str, *args, **kwds):
        global _g_is_in_comment_star_status
        tmp_str = tmp_str.strip()
        if _g_is_in_comment_star_status:
            if tmp_str.endswith("*/"):
                _g_is_in_comment_star_status = False
            return
        elif tmp_str.startswith("/*"):
            if not tmp_str.endswith("*/"):
                _g_is_in_comment_star_status = True
            return
        else:
            return f(tmp_str, *args, **kwds)

    return decorator


def comment_line_decorator(f):
    """
    检测"//"注释的装饰器
    :param f: 被装饰的函数
    :return: 装饰器
    """
    @wraps(f)
    def decorator(tmp_str, *args, **kwds):
        tmp_str = tmp_str.lstrip()
        if not tmp_str.startswith("//"):
            return f(tmp_str, *args, **kwds)

    return decorator
